#include <iostream>

using namespace std;

class Singleton
{
private:
    Singleton()
    {

    }

    ~Singleton()
    {
        cout << "~Singleton" << endl;   
    }
public:
    static Singleton * get_instance()
    {   
        //懒汉式：线程不安全
        // if(m_instance == nullptr)
        // {
        //     m_instance = new Singleton();
        // }

        static Singleton s; //static只会执行一次，

        return &s;
    }

    // static void free_instance()
    // {
    //     if(m_instance != nullptr)
    //     {
    //         delete m_instance;
    //     }

    //     m_instance = nullptr;   
    // }

    //static Singleton *m_instance;

    int m_num;
};

//Singleton * Singleton::m_instance = new Singleton();  //饿汉式：空间浪费


int main(int argc, char **argv)
{
    Singleton *s = Singleton::get_instance();
    Singleton *s1 = Singleton::get_instance();
    Singleton *s2 = Singleton::get_instance();

    cout << s << endl;
    cout << s1 << endl;
    
   //Singleton::free_instance();
    //s1->free_instance();
    
    return 0;
}